feat(routing): add NavigatorObserver support to MagicRouter#34
Merged
anilcancakir merged 2 commits intomasterfrom Apr 5, 2026
Merged
feat(routing): add NavigatorObserver support to MagicRouter#34anilcancakir merged 2 commits intomasterfrom
anilcancakir merged 2 commits intomasterfrom
Conversation
MagicRouter.instance.addObserver() enables Sentry, Firebase Analytics, and custom NavigatorObserver integration. Observers are passed to GoRouter automatically. Registration enforces same pre-build guard as routes.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds first-class NavigatorObserver registration to MagicRouter so apps can plug in analytics/monitoring observers (e.g., Sentry/Firebase) through Magic’s routing abstraction, while enforcing the same “register-before-build” guard used for route definitions.
Changes:
- Added observer registration API (
addObserver), read-only accessor (observers), and reset behavior toMagicRouter. - Wired registered observers into GoRouter via the
observersparameter during router build. - Documented the new capability across framework docs and added unit tests for the new API/guard behavior.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
lib/src/routing/magic_router.dart |
Stores observers, exposes getter, enforces pre-build guard, passes observers into GoRouter, clears on reset. |
test/routing/router_test.dart |
Adds coverage for storing observers, post-build guard, and reset behavior. |
skills/magic-framework/SKILL.md |
Updates reference index entry to include navigator observers in routing docs. |
skills/magic-framework/references/routing-navigation.md |
Adds a “Navigator Observers” section and timing gotcha. |
doc/basics/routing.md |
Adds user-facing docs section for registering observers in RouteServiceProvider. |
CHANGELOG.md |
Notes the feature in the Unreleased section. |
.claude/rules/routing.md |
Updates routing domain rules to mention observer support and timing constraint. |
…observers (#34) Renamed 'observers are passed to GoRouter' → 'observers persist after router build' since GoRouter doesn't publicly expose its observer list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #31
Summary
MagicRouter.instance.addObserver(NavigatorObserver)for analytics/monitoring integration (Sentry, Firebase, custom)observersparameter automaticallyStateErrorif called afterrouterConfigis accessedobserversgetter returns unmodifiable listreset()clears observersTest plan
addObserver()stores observer — verify viaobserversgetterrouterConfigaccessaddObserver()throwsStateErrorafter buildreset()clears observers on new instancedart analyze: zero warnings